require "util";
require "logUtil";
require "setting"

-- 书院 界面

shuYuan={}
function shuYuan.ui()

    x, y = findMultiColorInRegionFuzzy(0xfed737,"-38|-6|0x94100a,-2|40|0x92100a,-479|-17|0xfefdd5,-517|-15|0xfefbd0,-532|-13|0xfefacb,-532|-2|0xfeeaa3,-518|-5|0xfef0af,-503|-4|0xfeeeab,-494|16|0x3b0b00,-442|13|0xfed86f,-478|1|0xfee697,-471|-10|0xfef6c1,-452|-2|0xfeeaa3,-452|-18|0xfefdd6,-464|8|0xfedd7d", 85, 0, 0, 1079, 1919, 0, 0)

    if x > -1 then
        logger("书院.界面", LOG_DEBUG)
        return true
    end
end

--退出书院
function shuYuan.close()
    x, y = findMultiColorInRegionFuzzy(0xfed737,"-38|-6|0x94100a,-2|40|0x92100a,-479|-17|0xfefdd5,-517|-15|0xfefbd0,-532|-13|0xfefacb,-532|-2|0xfeeaa3,-518|-5|0xfef0af,-503|-4|0xfeeeab,-494|16|0x3b0b00,-442|13|0xfed86f,-478|1|0xfee697,-471|-10|0xfef6c1,-452|-2|0xfeeaa3,-452|-18|0xfefdd6,-464|8|0xfedd7d", 85, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("书院.界面关闭", LOG_DEBUG)
        return true
    end
end

--学习
function shuYuan.xueXi()
    x, y = findMultiColorInRegionFuzzy(0xfffcb2,"-70|7|0xfffcb2,-104|3|0xfffcb2,-131|1|0xfffcb2,18|2|0xfffcb2,95|15|0xfffcb2,-10|81|0x5b443b,-61|80|0x5b433a,136|91|0x0c070a,91|58|0x736e74,-71|187|0x080505,65|187|0x080405,166|-255|0x705a35", 85, 25, 332, 1053, 1885, 0, 0)
    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0xfffcb2,"0|-4|0xfffcb2,-70|8|0xfffcb2,-70|0|0xfffcb2,-131|1|0xfffcb2,95|14|0xfffcb2,0|79|0x5a4137,81|67|0x201d23,90|56|0x6e6970,129|91|0x0e0b12,-174|78|0x4f362c,-181|195|0x1b1112,164|192|0x1a1011", 90, 0, 0, 1079, 1919, 0, 0)
    end
    if x > -1 then


        click(x, y)
        logger("书院.学习", LOG_DEBUG)
        return true
    end
end

-- 派遣
function shuYuan.paiQian()
    x, y = findMultiColorInRegionFuzzy(0x38628e,"131|11|0x29456b,161|51|0x122e4a,-8|52|0x122c48,-54|39|0x15121e,56|-32|0x15121e,79|76|0x15121e,191|28|0x15121e,59|150|0x241f33,132|150|0x221d32", 85, 668, 489, 1005, 1620, 0, 0)
    if x > -1 then
        click(x, y)
        logger("书院.派遣", LOG_DEBUG)
        return true
    end
end

-- 关闭派遣界面
function shuYuan.paiQian_close()

end

-- 学习完成
function shuYuan.xueXiJieSu()
    x, y = findMultiColorInRegionFuzzy(0x5b443c,"86|-2|0x563e34,146|-22|0x736f73,136|-14|0x221f24,171|-27|0x221f25,181|-35|0x757175,188|16|0x0c0708,-48|89|0x1d1212,150|83|0x1d1212,8|-84|0x6cff00,54|-80|0x6cff00,46|-80|0x6cff00,88|-91|0x6cff00,74|-84|0x6cff00,91|-76|0x6cff00", 85, 19, 260, 1062, 1906, 0, 0)

    if x==-1 then
        x, y = findMultiColorInRegionFuzzy(0x6cff00,"-91|85|0x583f34,30|83|0x573e33,-139|74|0x7f614f,62|69|0x221f25,71|59|0x767174,110|96|0x0d0a0f,152|157|0x1b1112,-196|160|0x1b1112,-207|200|0x1b1112,-20|4|0x6cff00,-28|4|0x6cff00,-66|0|0x6cff00,13|-7|0x6cff00,17|7|0x6cff00", 90, 0, 0, 1079, 1919, 0, 0)

    end
    if x > -1 then
        click(x, y)
        logger("书院.学习完成", LOG_DEBUG)
        return true
    end
end


function shuYuan.run()

    ZhuJieMian.shuYuan();
    local flag = shuYuan.ui()
    if not (flag) then
        return
    end


    for i = 1, 2 do

        mSleep(500)
        local funcArr = { shuYuan.xueXi, shuYuan.paiQian, shuYuan.xueXiJieSu }
				flag=true
        while flag do
            for i, func in ipairs(funcArr) do
                flag = func()
                if flag then
                    break
                end
                mSleep(100)
            end
            mSleep(2000)
            wangLuoLianJieShiBai()
        end

        logger("书院.开始翻页", LOG_DEBUG)
        szMove(563,1816, 537,511)
        mSleep(3000)
    end


    shuYuan.close()

end






